<?php
namespace app\web\model;

use cubox\Model;
use cubox\Cubox;

class Page extends Model{
    public function frontData($data){
        try{
            $param = json_decode($data['param'],true);
        }catch(\Exception $e){
            $param = array();
        }

        $re = $param;
        $re['title'] =  $data['title'];
        $re['row'] = $data;
        $re['path'] = $this->getRoute($data);
        
        return $re;
    }

    public function getRoute($data){
        $route = $data['route'];
        if ($data['route_type']=='default'){
            $route = Cubox::url('web','index','page',['id'=>$data['page_id']]);
        }

        if ($data['route_type']=='root'){
            $route  = '/'.$data['route'];
        }
        return $route;
    }
}